package com.hanthink.web.controller.manhour;

import java.util.List;

import com.hanthink.common.core.domain.model.LoginUser;
import com.hanthink.common.utils.ServletUtils;
import com.hanthink.framework.web.service.TokenService;
import com.hanthink.system.domain.manhour.ProductionPlanInShift;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hanthink.common.annotation.Log;
import com.hanthink.common.core.controller.BaseController;
import com.hanthink.common.core.domain.AjaxResult;
import com.hanthink.common.enums.BusinessType;
import com.hanthink.system.domain.manhour.ProductionPlanAssistInShift;
import com.hanthink.system.service.manhour.IProductionPlanAssistInShiftService;
import com.hanthink.common.utils.poi.ExcelUtil;
import com.hanthink.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 辅助用工上报Controller
 * 
 * @author hanthink
 * @date 2021-12-09
 */
@RestController
@RequestMapping("/manhour/ProductionPlanAssistInShift")
public class ProductionPlanAssistInShiftController extends BaseController
{
    @Autowired
    private IProductionPlanAssistInShiftService productionPlanAssistInShiftService;

    @Autowired
    private TokenService tokenService;

    /**
     * 查询辅助用工上报列表
     */
    @PreAuthorize("@ss.hasPermi('manhour:ProductionPlanAssistInShift:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProductionPlanAssistInShift productionPlanAssistInShift)
    {
        startPage();
        List<ProductionPlanAssistInShift> list = productionPlanAssistInShiftService.selectProductionPlanAssistInShiftList(productionPlanAssistInShift);
        return getDataTable(list);
    }

    /**
     * 导出辅助用工上报列表
     */
    @PreAuthorize("@ss.hasPermi('manhour:ProductionPlanAssistInShift:export')")
    @Log(title = "辅助用工上报", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ProductionPlanAssistInShift productionPlanAssistInShift)
    {
        List<ProductionPlanAssistInShift> list = productionPlanAssistInShiftService.selectProductionPlanAssistInShiftList(productionPlanAssistInShift);
        ExcelUtil<ProductionPlanAssistInShift> util = new ExcelUtil<ProductionPlanAssistInShift>(ProductionPlanAssistInShift.class);
        return util.exportExcel(list, "ProductionPlanAssistInShift");
    }

    /**
     * 获取辅助用工上报详细信息
     */
    //@PreAuthorize("@ss.hasPermi('manhour:ProductionPlanAssistInShift:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(productionPlanAssistInShiftService.selectProductionPlanAssistInShiftById(id));
    }

    /**
     * 新增辅助用工上报
     */
    @PreAuthorize("@ss.hasPermi('manhour:ProductionPlanAssistInShift:add')")
    @Log(title = "辅助用工上报", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductionPlanAssistInShift productionPlanAssistInShift)
    {
        return toAjax(productionPlanAssistInShiftService.insertProductionPlanAssistInShift(productionPlanAssistInShift));
    }

    /**
     * 修改辅助用工上报
     */
    @PreAuthorize("@ss.hasPermi('manhour:ProductionPlanAssistInShift:edit')")
    @Log(title = "辅助用工上报", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductionPlanAssistInShift productionPlanAssistInShift)
    {
        return toAjax(productionPlanAssistInShiftService.updateProductionPlanAssistInShift(productionPlanAssistInShift));
    }

    /**
     * 删除辅助用工上报
     */
    @PreAuthorize("@ss.hasPermi('manhour:ProductionPlanAssistInShift:remove')")
    @Log(title = "辅助用工上报", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(productionPlanAssistInShiftService.deleteProductionPlanAssistInShiftByIds(ids));
    }

    @GetMapping("/importTemplate") // 下载导入模板 fmc
    public AjaxResult importTemplate() {
        ExcelUtil<ProductionPlanAssistInShift> util = new ExcelUtil<ProductionPlanAssistInShift>(ProductionPlanAssistInShift.class);
        return util.importTemplateExcel("实际用工数据上报");
    }

    @Log(title = "实际辅助工数据", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('manhour:ProductionPlanAssistInShift:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception {
        ExcelUtil<ProductionPlanAssistInShift> util = new ExcelUtil<ProductionPlanAssistInShift>(ProductionPlanAssistInShift.class);
        List<ProductionPlanAssistInShift> itemList = util.importExcel(file.getInputStream());
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        String operName = loginUser.getUsername();
        String message = productionPlanAssistInShiftService.importPlanitem(itemList, updateSupport, operName);
        return AjaxResult.success(message);
    }
}
